package com.sun.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.mapper.HeatMapper;
import com.sun.pojo.Heat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Connection;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Controller
public class HeatController {

    @Autowired
    HeatMapper heatMapper;


    /*
    *
    * 软科排名
    * */
    @RequestMapping("/heat/{pageNo}")
    public Object page(@PathVariable("pageNo") Integer pageNo,
                       Model model
    ) {
        PageHelper.startPage(pageNo,10);
        List<Heat> list = heatMapper.selectAll();
        PageInfo<Heat> page = new PageInfo<>(list,5);
        model.addAttribute("list",page);
        System.out.println(page);
//        return page;
        return "heat/list";
    }

    @RequestMapping("/heat")
    public String po(@RequestParam(value = "pageNo1",defaultValue = "1") Integer pageNo1,
                     Model model){
        PageHelper.startPage(pageNo1,10);
        List<Heat> list = heatMapper.selectAll();
        PageInfo<Heat> page1 = new PageInfo<>(list,5);
        model.addAttribute("list",page1);
        System.out.println(page1);
        return "heat/list";
    }
    @RequestMapping("/heats")
    public String select(@RequestParam("name") String name,
//                         @PathVariable("pageNo") Integer pageNo,
                         Model model){
        List<Heat> list = heatMapper.selectDate(name);
        PageInfo<Heat> page1 = new PageInfo<>(list, 5);
        model.addAttribute("list", page1);
        return "heat/list";
    }


    /*
    * 查询人气值top10
    * */
    @RequestMapping("/heat/data1")
    @ResponseBody
    public Collection<Heat> selectPopuTop10(){
        Collection<Heat> list=  heatMapper.selectPopuTop10();
        System.out.println(list);
        return list ;
    }


    /*
     * 查询授予学位类型
     * */
    @RequestMapping("/heat/selectDegree")
    @ResponseBody
    public Object selectDegree(){
        Collection<Map<String, Integer>> list=  heatMapper.selectDegree();
        System.out.println(list);
        return list ;
    }

    /*
     * 查询授予修业年限
     * */
    @RequestMapping("/heat/selectYear")
    @ResponseBody
    public Object selectYear(){
        Collection<Map<String, Integer>> list=  heatMapper.selectYear();
        System.out.println(list);
        return list ;
    }

    /*
     * 查询既有四年也有五年的专业
     * */
    @RequestMapping("/heat/selectNoYear")
    @ResponseBody
    public Object selectNoYear(){
        Collection<Map<String, Integer>> list = heatMapper.selectNoYear();
        System.out.println(list);
        return list ;
    }
    /*
    * 进入可视化界面
    * */
    @RequestMapping("/heat/echarts")
    public String Ecahrts() {
        return "heat/echarts";
    }
}
